<?php
namespace Api\Controller;
use Think\Controller;
use Think\Vender;
class WeixinpayController extends BaseController{
	public function __construct(){
		parent::__construct(); 
	}

	public function index(){
		
	}

	public function wxpay(){
		$openid=I('post.openid');
		$commoditylist=$_POST['commodity'];
		$data=json_decode($commoditylist,true);
		$price=0;
		$order_no=time().rand(1000,10000); //商户订单号
		$order['openid']=$openid;
		$order['order_no']=$order_no;
		$order['create_time']=time();
		foreach ($data as $key => $value) {
			$price+=intval($data[$key]['count']*$data[$key]['price']);
			$order['danjia']=intval($data[$key]['price']);
			$order['price']=intval($data[$key]['count']*$data[$key]['price']);
			$order['shop_id']=intval($data[$key]['id']);
			$order['shop_count']=intval($data[$key]['count']);
			
			M('ad_order')->add($order);

		}
		// $pr=M('ad_order')->field('price')->where(['order'=>$order_no])->select();
		// $sum=0;
		// foreach ($pr as $key => $value) {
		// 	$sum+=intval($pr[$key]['price']);
		// }
		// var_dump($sum);
		//$this->ajaxReturn($this->pay($openid,$price,$detail));
		$this->ajaxReturn($this->pay($openid,$price,$order_no));

	}

	public function ceshi(){
		   $data=M('shopcar')->select();
        echo json_encode($data);
        //json_decode
	}
}